// 1. 定义内容类型状态枚举
export enum ContentState {
  UNKNOWN = 'UNKNOWN',
  VIDEO = 'VIDEO',
  IMAGE_TEXT = 'IMAGE_TEXT'
}
  
  // 2. 定义内容检测事件枚举
  enum DetectionEvent {
    DETECT_VIDEO = 'DETECT_VIDEO',
    DETECT_IMAGE_TEXT = 'DETECT_IMAGE_TEXT',
    RESET = 'RESET'
  }
  
  // 3. 定义状态转移规则类型
  type ContentTransitionRules = {
    [key in ContentState]: {
      [event in DetectionEvent]?: ContentState;
    };
  };
  
  // 4. 实现内容状态机类
  export class ContentStateMachine {
    private currentState: ContentState;
    private readonly transitionRules: ContentTransitionRules;
  
    constructor() {
      this.currentState = ContentState.UNKNOWN;
      this.transitionRules = {
        [ContentState.UNKNOWN]: {
          [DetectionEvent.DETECT_VIDEO]: ContentState.VIDEO,
          [DetectionEvent.DETECT_IMAGE_TEXT]: ContentState.IMAGE_TEXT
        },
        [ContentState.VIDEO]: {
          [DetectionEvent.RESET]: ContentState.UNKNOWN
        },
        [ContentState.IMAGE_TEXT]: {
          [DetectionEvent.RESET]: ContentState.UNKNOWN
        }
      };
    }
  
    // 获取当前内容类型状态
    get state(): ContentState {
      return this.currentState;
    }
  
    // 处理内容检测事件
    dispatch(event: DetectionEvent): void {
      const nextState = this.transitionRules[this.currentState][event];
      if (nextState) {
        console.log(`内容状态变更: ${this.currentState} -> ${nextState} (触发事件: ${event})`);
        this.currentState = nextState;
      } else {
        console.warn(`无效状态转移: 当前状态 ${this.currentState} 无法处理事件 ${event}`);
      }
    }
  }